//
//  BaseNavViewController.swift
//  微博个人swift
//
//  Created by 李灏 on 16/2/23.
//  Copyright © 2016年 lh. All rights reserved.
//

import UIKit

class BaseNavViewController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //一旦自定义以后原来的手势就失效了
        self.interactivePopGestureRecognizer?.delegate = self
        
    }
    //自定义返回按钮
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //获取子视图控制器的数量
        let count = childViewControllers.count
        if count != 0 {
            //隐藏下边
            viewController.hidesBottomBarWhenPushed = true
            let btn = UIButton(backImageName: nil, title: "返回", textColor: UIColor.darkGrayColor(), imageName: "navigationbar_back_withtext", fontSize: 16)
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        }
        super.pushViewController(viewController, animated: animated)
    }
    @objc private func back() {
        self.popViewControllerAnimated(true)
    }
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        //        if childViewControllers.count > 1 {
        //            print("嘿嘿嘿嘿")
        //            return true
        //        }
        //        return false
        
        return childViewControllers.count > 1
    }
}
